package com.cloudm.technician.ui.modules.cloudm_box.pic_preview

import android.app.Activity
import android.os.Bundle
import android.view.View
import com.cloudm.technician.R
import com.cloudm.technician.extensions.loadImage
import com.cloudm.technician.ui.base.BaseFragment
import com.cloudm.technician.ui.base.BasePresenter
import kotlinx.android.synthetic.main.frgment_pic_preview.*

/**
 * 作者: wesley
 * 时间: 2017/12/23
 * 描述: ui
 */
class PicPreviewFragment : BaseFragment<BasePresenter>() {

    private var url: String = ""

    override val resource: Int
        get() = R.layout.frgment_pic_preview

    companion object {
        fun newInstance(url: String) = PicPreviewFragment().apply {
            arguments = Bundle().apply {
                putString("url", url)
            }
        }
    }

    override fun initInject() {

    }

    override fun handleBundle(bundle: Bundle) {
        url = bundle.getString("url")
    }

    override fun initVariables() {

    }

    override fun initViews(view: View) {
        ivDeleteImage.loadImage(url)
    }

    override fun initListener() {

    }

    fun deleteImage() {
        showPromptDialog(R.string.make_sure_delete_image, negativeButton = R.string.think_again)
    }

    override fun onPositiveButtonClick() {
        val activity = mContext as? PicPreviewActivity ?: return
        activity.setResult(Activity.RESULT_OK)
        activity.finish()
    }
}